<!doctype html><html lang="en">
 <head>
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  <title>CSS Nesting Module</title>
  <meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
  <meta content="exploring" name="csswg-work-status">
  <meta content="ED" name="w3c-status">
  <meta content="This module introduces the ability to nest one style rule inside another, with the selector of the child rule relative to the selector of the parent rule.  This increases the modularity and maintainability of CSS stylesheets." name="abstract">
  <link href="../default.css" rel="stylesheet" type="text/css">
  <link href="../csslogo.ico" rel="shortcut icon" type="image/x-icon">
<style>
  body {
    background: url("https://www.w3.org/StyleSheets/TR/logo-ED") top left no-repeat;
  }
  </style>
  <link href="https://drafts.csswg.org/css-nesting/" rel="canonical">
<style>/* style-md-lists */

/* This is a weird hack for me not yet following the commonmark spec
   regarding paragraph and lists. */
[data-md] > :first-child {
    margin-top: 0;
}
[data-md] > :last-child {
    margin-bottom: 0;
}</style>
<style>/* style-selflinks */

.heading, .issue, .note, .example, li, dt {
    position: relative;
}
a.self-link {
    position: absolute;
    top: 0;
    left: calc(-1 * (3.5rem - 26px));
    width: calc(3.5rem - 26px);
    height: 2em;
    text-align: center;
    border: none;
    transition: opacity .2s;
    opacity: .5;
}
a.self-link:hover {
    opacity: 1;
}
.heading > a.self-link {
    font-size: 83%;
}
li > a.self-link {
    left: calc(-1 * (3.5rem - 26px) - 2em);
}
dfn > a.self-link {
    top: auto;
    left: auto;
    opacity: 0;
    width: 1.5em;
    height: 1.5em;
    background: gray;
    color: white;
    font-style: normal;
    transition: opacity .2s, background-color .2s, color .2s;
}
dfn:hover > a.self-link {
    opacity: 1;
}
dfn > a.self-link:hover {
    color: black;
}

a.self-link::before            { content: "¶"; }
.heading > a.self-link::before { content: "§"; }
dfn > a.self-link::before      { content: "#"; }</style>
<style>/* style-counters */

body {
    counter-reset: example figure issue;
}
.issue {
    counter-increment: issue;
}
.issue:not(.no-marker)::before {
    content: "Issue " counter(issue);
}

.example {
    counter-increment: example;
}
.example:not(.no-marker)::before {
    content: "Example " counter(example);
}
.invalid.example:not(.no-marker)::before,
.illegal.example:not(.no-marker)::before {
    content: "Invalid Example" counter(example);
}

figcaption {
    counter-increment: figure;
}
figcaption:not(.no-marker)::before {
    content: "Figure " counter(figure) " ";
}</style>
<style>/* style-autolinks */

.css.css, .property.property, .descriptor.descriptor {
    color: #005a9c;
    font-size: inherit;
    font-family: inherit;
}
.css::before, .property::before, .descriptor::before {
    content: "‘";
}
.css::after, .property::after, .descriptor::after {
    content: "’";
}
.property, .descriptor {
    /* Don't wrap property and descriptor names */
    white-space: nowrap;
}
.type { /* CSS value <type> */
    font-style: italic;
}
pre .property::before, pre .property::after {
    content: "";
}
[data-link-type="property"]::before,
[data-link-type="propdesc"]::before,
[data-link-type="descriptor"]::before,
[data-link-type="value"]::before,
[data-link-type="function"]::before,
[data-link-type="at-rule"]::before,
[data-link-type="selector"]::before,
[data-link-type="maybe"]::before {
    content: "‘";
}
[data-link-type="property"]::after,
[data-link-type="propdesc"]::after,
[data-link-type="descriptor"]::after,
[data-link-type="value"]::after,
[data-link-type="function"]::after,
[data-link-type="at-rule"]::after,
[data-link-type="selector"]::after,
[data-link-type="maybe"]::after {
    content: "’";
}

[data-link-type].production::before,
[data-link-type].production::after,
.prod [data-link-type]::before,
.prod [data-link-type]::after {
    content: "";
}

[data-link-type=element],
[data-link-type=element-attr] {
    font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;
    font-size: .9em;
}
[data-link-type=element]::before { content: "<" }
[data-link-type=element]::after  { content: ">" }

[data-link-type=biblio] {
    white-space: pre;
}</style>
<style>/* style-dfn-panel */

.dfn-panel {
    position: absolute;
    z-index: 35;
    height: auto;
    width: -webkit-fit-content;
    width: fit-content;
    max-width: 300px;
    max-height: 500px;
    overflow: auto;
    padding: 0.5em 0.75em;
    font: small Helvetica Neue, sans-serif, Droid Sans Fallback;
    background: #DDDDDD;
    color: black;
    border: outset 0.2em;
}
.dfn-panel:not(.on) { display: none; }
.dfn-panel * { margin: 0; padding: 0; text-indent: 0; }
.dfn-panel > b { display: block; }
.dfn-panel a { color: black; }
.dfn-panel a:not(:hover) { text-decoration: none !important; border-bottom: none !important; }
.dfn-panel > b + b { margin-top: 0.25em; }
.dfn-panel ul { padding: 0; }
.dfn-panel li { list-style: inside; }
.dfn-panel.activated {
    display: inline-block;
    position: fixed;
    left: .5em;
    bottom: 2em;
    margin: 0 auto;
    max-width: calc(100vw - 1.5em - .4em - .5em);
    max-height: 30vh;
}

.dfn-paneled { cursor: pointer; }
</style>
<style>/* style-syntax-highlighting */

.highlight:not(.idl) { background: hsl(24, 20%, 95%); }
code.highlight { padding: .1em; border-radius: .3em; }
pre.highlight, pre > code.highlight { display: block; padding: 1em; margin: .5em 0; overflow: auto; border-radius: 0; }
c-[a] { color: #990055 } /* Keyword.Declaration */
c-[b] { color: #990055 } /* Keyword.Type */
c-[c] { color: #708090 } /* Comment */
c-[d] { color: #708090 } /* Comment.Multiline */
c-[e] { color: #0077aa } /* Name.Attribute */
c-[f] { color: #669900 } /* Name.Tag */
c-[g] { color: #222222 } /* Name.Variable */
c-[k] { color: #990055 } /* Keyword */
c-[l] { color: #000000 } /* Literal */
c-[m] { color: #000000 } /* Literal.Number */
c-[n] { color: #0077aa } /* Name */
c-[o] { color: #999999 } /* Operator */
c-[p] { color: #999999 } /* Punctuation */
c-[s] { color: #a67f59 } /* Literal.String */
c-[t] { color: #a67f59 } /* Literal.String.Single */
c-[u] { color: #a67f59 } /* Literal.String.Double */
c-[cp] { color: #708090 } /* Comment.Preproc */
c-[c1] { color: #708090 } /* Comment.Single */
c-[cs] { color: #708090 } /* Comment.Special */
c-[kc] { color: #990055 } /* Keyword.Constant */
c-[kn] { color: #990055 } /* Keyword.Namespace */
c-[kp] { color: #990055 } /* Keyword.Pseudo */
c-[kr] { color: #990055 } /* Keyword.Reserved */
c-[ld] { color: #000000 } /* Literal.Date */
c-[nc] { color: #0077aa } /* Name.Class */
c-[no] { color: #0077aa } /* Name.Constant */
c-[nd] { color: #0077aa } /* Name.Decorator */
c-[ni] { color: #0077aa } /* Name.Entity */
c-[ne] { color: #0077aa } /* Name.Exception */
c-[nf] { color: #0077aa } /* Name.Function */
c-[nl] { color: #0077aa } /* Name.Label */
c-[nn] { color: #0077aa } /* Name.Namespace */
c-[py] { color: #0077aa } /* Name.Property */
c-[ow] { color: #999999 } /* Operator.Word */
c-[mb] { color: #000000 } /* Literal.Number.Bin */
c-[mf] { color: #000000 } /* Literal.Number.Float */
c-[mh] { color: #000000 } /* Literal.Number.Hex */
c-[mi] { color: #000000 } /* Literal.Number.Integer */
c-[mo] { color: #000000 } /* Literal.Number.Oct */
c-[sb] { color: #a67f59 } /* Literal.String.Backtick */
c-[sc] { color: #a67f59 } /* Literal.String.Char */
c-[sd] { color: #a67f59 } /* Literal.String.Doc */
c-[se] { color: #a67f59 } /* Literal.String.Escape */
c-[sh] { color: #a67f59 } /* Literal.String.Heredoc */
c-[si] { color: #a67f59 } /* Literal.String.Interpol */
c-[sx] { color: #a67f59 } /* Literal.String.Other */
c-[sr] { color: #a67f59 } /* Literal.String.Regex */
c-[ss] { color: #a67f59 } /* Literal.String.Symbol */
c-[vc] { color: #0077aa } /* Name.Variable.Class */
c-[vg] { color: #0077aa } /* Name.Variable.Global */
c-[vi] { color: #0077aa } /* Name.Variable.Instance */
c-[il] { color: #000000 } /* Literal.Number.Integer.Long */
</style>
 <body class="h-entry">
  <div class="head">
   <p data-fill-with="logo"><a class="logo" href="https://www.w3.org/"> <img alt="W3C" height="48" src="https://www.w3.org/StyleSheets/TR/2016/logos/W3C" width="72"> </a> </p>
   <h1 class="p-name no-ref" id="title">CSS Nesting Module</h1>
   <h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Editor’s Draft, <time class="dt-updated" datetime="1970-01-01">1 January 1970</time></span></h2>
   <details>
    <summary>Specification Metadata</summary>
    <div data-fill-with="spec-metadata">
     <dl>
      <dt>This version:
      <dd><a class="u-url" href="https://drafts.csswg.org/css-nesting/">https://drafts.csswg.org/css-nesting/</a>
      <dt class="editor">Editor:
      <dd class="editor p-author h-card vcard" data-editor-id="42199"><a class="p-name fn u-url url" href="http://xanthir.com/contact/">Tab Atkins Jr.</a> (<span class="p-org org">Google</span>)
      <dt>Suggest an Edit for this Spec:
      <dd><a href="https://github.com/w3c/csswg-drafts/blob/master/css-nesting-1/Overview.bs">GitHub Editor</a>
      <dt>Issue Tracking:
      <dd><a href="https://github.com/w3c/csswg-drafts/labels/css-nesting-1">GitHub Issues</a>
     </dl>
    </div>
   </details>
   <div data-fill-with="warning"></div>
   <p class="copyright" data-fill-with="copyright"><a href="https://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 1970 <a href="https://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href="https://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="https://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href="https://www.keio.ac.jp/">Keio</a>, <a href="https://ev.buaa.edu.cn/">Beihang</a>). W3C <a href="https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document">permissive document license</a> rules apply. </p>
   <hr title="Separator for header">
  </div>
  <div class="p-summary" data-fill-with="abstract">
   <h2 class="no-num no-toc no-ref heading settled" id="abstract"><span class="content">Abstract</span></h2>
   <p>This module introduces the ability to nest one style rule inside another, with the selector of the child rule relative to the selector of the parent rule.  This increases the modularity and maintainability of CSS stylesheets.</p>
    <a href="https://www.w3.org/TR/CSS/">CSS</a> is a language for describing the rendering of structured documents
(such as HTML and XML)
on screen, on paper, etc. 
  </div>
  <h2 class="no-num no-toc no-ref heading settled" id="status"><span class="content">Status of this document</span></h2>
  <div data-fill-with="status">
   <p> This is a public copy of the editors’ draft.
	It is provided for discussion only and may change at any moment.
	Its publication here does not imply endorsement of its contents by W3C.
	Don’t cite this document other than as work in progress. </p>
   <p> <a href="https://github.com/w3c/csswg-drafts/issues">GitHub Issues</a> are preferred for discussion of this specification.
	When filing an issue, please put the text “css-nesting” in the title,
	preferably like this:
	“[css-nesting] <i data-lt>…summary of comment…</i>”.
	All issues and comments are <a href="https://lists.w3.org/Archives/Public/public-css-archive/">archived</a>,
	and there is also a <a href="https://lists.w3.org/Archives/Public/www-style/">historical archive</a>. </p>
   <p> This document was produced by the <a href="https://www.w3.org/Style/CSS/">CSS Working Group</a>. </p>
   <p> This document was produced by a group operating under
	the <a href="https://www.w3.org/Consortium/Patent-Policy/">W3C Patent Policy</a>.
	W3C maintains a <a href="https://www.w3.org/2004/01/pp-impl/32061/status" rel="disclosure">public list of any patent disclosures</a> made in connection with the deliverables of the group;
	that page also includes instructions for disclosing a patent.
	An individual who has actual knowledge of a patent which the individual believes contains <a href="https://www.w3.org/Consortium/Patent-Policy/#def-essential">Essential Claim(s)</a> must disclose the information in accordance with <a href="https://www.w3.org/Consortium/Patent-Policy/#sec-Disclosure">section 6 of the W3C Patent Policy</a>. </p>
   <p> This document is governed by the <a href="https://www.w3.org/2019/Process-20190301/" id="w3c_process_revision">1 March 2019 W3C Process Document</a>. </p>
   <p></p>
  </div>
  <div data-fill-with="at-risk"></div>
  <nav data-fill-with="table-of-contents" id="toc">
   <h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
   <ol class="toc" role="directory">
    <li>
     <a href="#intro"><span class="secno">1</span> <span class="content"> Introduction</span></a>
     <ol class="toc">
      <li><a href="#placement"><span class="secno">1.1</span> <span class="content"> Module Interactions</span></a>
      <li><a href="#values"><span class="secno">1.2</span> <span class="content"> Values</span></a>
      <li><a href="#motivation"><span class="secno">1.3</span> <span class="content"> Motivation</span></a>
     </ol>
    <li><a href="#nest-selector"><span class="secno">2</span> <span class="content">Nesting Selector: the <span class="css">&amp;</span> selector</span></a>
    <li>
     <a href="#nesting"><span class="secno">3</span> <span class="content">Nesting Style Rules</span></a>
     <ol class="toc">
      <li><a href="#direct"><span class="secno">3.1</span> <span class="content">Direct Nesting</span></a>
      <li><a href="#at-nest"><span class="secno">3.2</span> <span class="content">The Nesting At-Rule: <span class="css">@nest</span></span></a>
      <li><a href="#mixing"><span class="secno">3.3</span> <span class="content">Mixing Nesting Rules and Declarations</span></a>
     </ol>
    <li><a href="#cssom"><span class="secno">4</span> <span class="content">CSS Object Model Modifications</span></a>
    <li>
     <a href="#conformance"><span class="secno"></span> <span class="content"> Conformance</span></a>
     <ol class="toc">
      <li><a href="#document-conventions"><span class="secno"></span> <span class="content"> Document conventions</span></a>
      <li><a href="#conform-classes"><span class="secno"></span> <span class="content"> Conformance classes</span></a>
      <li>
       <a href="#conform-responsible"><span class="secno"></span> <span class="content"> Requirements for Responsible Implementation of CSS</span></a>
       <ol class="toc">
        <li><a href="#conform-partial"><span class="secno"></span> <span class="content"> Partial Implementations</span></a>
        <li><a href="#conform-future-proofing"><span class="secno"></span> <span class="content"> Implementations of Unstable and Proprietary Features</span></a>
        <li><a href="#conform-testing"><span class="secno"></span> <span class="content"> Implementations of CR-level Features</span></a>
       </ol>
     </ol>
    <li>
     <a href="#index"><span class="secno"></span> <span class="content">Index</span></a>
     <ol class="toc">
      <li><a href="#index-defined-here"><span class="secno"></span> <span class="content">Terms defined by this specification</span></a>
      <li><a href="#index-defined-elsewhere"><span class="secno"></span> <span class="content">Terms defined by reference</span></a>
     </ol>
    <li>
     <a href="#references"><span class="secno"></span> <span class="content">References</span></a>
     <ol class="toc">
      <li><a href="#normative"><span class="secno"></span> <span class="content">Normative References</span></a>
      <li><a href="#informative"><span class="secno"></span> <span class="content">Informative References</span></a>
     </ol>
    <li><a href="#issues-index"><span class="secno"></span> <span class="content">Issues Index</span></a>
   </ol>
  </nav>
  <main>
   <h2 class="heading settled" data-level="1" id="intro"><span class="secno">1. </span><span class="content"> Introduction</span><a class="self-link" href="#intro"></a></h2>
   <p><em>This section is not normative.</em></p>
   <p>This module describes support for nesting a style rule within another style rule,
	allowing the inner rule’s selector to reference the elements matched by the outer rule.
	This feature allows related styles to be aggregated into a single structure within the CSS document,
	improving readability and maintainability.</p>
   <h3 class="heading settled" data-level="1.1" id="placement"><span class="secno">1.1. </span><span class="content"> Module Interactions</span><a class="self-link" href="#placement"></a></h3>
   <p>This module introduces new parser rules that extend the <a data-link-type="biblio" href="#biblio-css21">[CSS21]</a> parser model.
	This module introduces selectors that extend the <a data-link-type="biblio" href="#biblio-selectors4">[SELECTORS4]</a> module.</p>
   <h3 class="heading settled" data-level="1.2" id="values"><span class="secno">1.2. </span><span class="content"> Values</span><a class="self-link" href="#values"></a></h3>
   <p>This specification does not define any new properties or values.</p>
   <h3 class="heading settled" data-level="1.3" id="motivation"><span class="secno">1.3. </span><span class="content"> Motivation</span><a class="self-link" href="#motivation"></a></h3>
   <p>CSS Rules for even moderately complicated web pages include lots of duplication for the purpose of styling related content.
	For example, here is a portion of the CSS markup for one version of the <a data-link-type="biblio" href="#biblio-css3color">[CSS3COLOR]</a> module:</p>
   <div class="example" id="example-df188c81">
    <a class="self-link" href="#example-df188c81"></a> 
<pre class="lang-css highlight"><c- f>table.colortable td </c-><c- p>{</c->
  <c- k>text-align</c-><c- p>:</c->center<c- p>;</c->
<c- p>}</c->
<c- f>table.colortable td.c </c-><c- p>{</c->
  <c- k>text-transform</c-><c- p>:</c->uppercase<c- p>;</c->
<c- p>}</c->
<c- f>table.colortable td:first-child, table.colortable td:first-child+td </c-><c- p>{</c->
  <c- k>border</c-><c- p>:</c-><c- m>1</c-><c- l>px</c-> solid black<c- p>;</c->
<c- p>}</c->
<c- f>table.colortable th </c-><c- p>{</c->
  <c- k>text-align</c-><c- p>:</c->center<c- p>;</c->
  <c- k>background</c-><c- p>:</c->black<c- p>;</c->
  <c- k>color</c-><c- p>:</c->white<c- p>;</c->
<c- p>}</c->
</pre>
   </div>
   <p>Nesting allows the grouping of related style rules, like this:</p>
   <div class="example" id="example-aecb8796">
    <a class="self-link" href="#example-aecb8796"></a> 
<pre class="lang-css highlight"><c- f>table.colortable </c-><c- p>{</c->
  &amp; td {
    text-align:center;
    &amp;.c { text-transform:uppercase }
    &amp;:first-child, &amp;:first-child + td { border:1px solid black }
  }
  &amp; th {
    text-align:center;
    background:black;
    color:white;
  }
}
</pre>
   </div>
   <p>Besides removing duplication,
	the grouping of related rules improves the readability and maintainability of the resulting CSS.</p>
   <h2 class="heading settled" data-level="2" id="nest-selector"><span class="secno">2. </span><span class="content">Nesting Selector: the <a class="css" data-link-type="maybe" href="#selectordef-" id="ref-for-selectordef-">&amp;</a> selector</span><a class="self-link" href="#nest-selector"></a></h2>
   <p>When using a <a data-link-type="dfn" href="#nested-style-rule" id="ref-for-nested-style-rule">nested style rule</a>,
	one must be able to refer to the elements matched by the parent rule;
	that is, after all, <em>the entire point of nesting</em>.
	To accomplish that,
	this specification defines a new selector,
	the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="nesting-selector">nesting selector</dfn>,
	written as an ASCII ampersand <dfn class="dfn-paneled css" data-dfn-type="selector" data-export id="selectordef-">&amp;</dfn>.</p>
   <p>When used in the selector of a <a data-link-type="dfn" href="#nested-style-rule" id="ref-for-nested-style-rule①">nested style rule</a>,
	the <a data-link-type="dfn" href="#nesting-selector" id="ref-for-nesting-selector">nesting selector</a> represents the elements matched by the parent rule.
	When used in any other context,
	it represents nothing.
	(That is, it’s valid, but matches no elements.)</p>
   <div class="note" role="note">
     The <a data-link-type="dfn" href="#nesting-selector" id="ref-for-nesting-selector①">nesting selector</a> can be desugared
		by replacing it with the parent style rule’s selector,
		wrapped in a <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/selectors-4/#selectordef-matches" id="ref-for-selectordef-matches">:matches()</a> selector.
		For example, 
<pre class="lang-css highlight"><c- f>a, b </c-><c- p>{</c->
  &amp; c { color: blue; }
}
</pre>
    <p>is equivalent to</p>
<pre class="lang-css highlight"><c- f>:matches(a, b) c </c-><c- p>{</c-> <c- k>color</c-><c- p>:</c-> blue<c- p>;</c-> <c- p>}</c->
</pre>
   </div>
   <p>The <a data-link-type="dfn" href="https://drafts.csswg.org/selectors-4/#specificity" id="ref-for-specificity">specificity</a> of the <a data-link-type="dfn" href="#nesting-selector" id="ref-for-nesting-selector②">nesting selector</a> is equal to the largest specificity among the parent style rule’s selector
	that match the given element.</p>
   <div class="example" id="example-1353884a">
    <a class="self-link" href="#example-1353884a"></a> For example, given the following style rules: 
<pre class="lang-css highlight"><c- f>#a, .b </c-><c- p>{</c->
  &amp; c { color: blue; }
}
</pre>
    <p>Then in a DOM structure like</p>
<pre class="lang-html highlight"><c- p>&lt;</c-><c- f>div</c-> <c- e>id</c-><c- o>=</c-><c- s>a</c-><c- p>></c->
  <c- p>&lt;</c-><c- f>c</c-><c- p>></c->foo<c- p>&lt;/</c-><c- f>c</c-><c- p>></c->
<c- p>&lt;/</c-><c- f>div</c-><c- p>></c->
</pre>
    <p>the <a class="css" data-link-type="maybe" href="#selectordef-" id="ref-for-selectordef-①">&amp;</a> selector has specificity [1,0,0]
		because it matches due to the <span class="css">#a</span> selector,
		giving the entire <a class="css" data-link-type="propdesc" href="https://drafts.csswg.org/css-color-4/#propdef-color" id="ref-for-propdef-color">color: blue</a> rule a specificity of [1,0,1].</p>
   </div>
   <p class="note" role="note"><span>Note:</span> This specificity is intentionally equivalent to that of the desugaring described above.</p>
   <p>The <a data-link-type="dfn" href="#nesting-selector" id="ref-for-nesting-selector③">nesting selector</a> is allowed anywhere in a <a data-link-type="dfn" href="https://drafts.csswg.org/selectors-4/#compound" id="ref-for-compound">compound selector</a>,
	even before a <a data-link-type="dfn" href="https://drafts.csswg.org/selectors-4/#type-selector" id="ref-for-type-selector">type selector</a>,
	violating the normal restrictions on ordering within a <span id="ref-for-compound①">compound selector</span>.</p>
   <p class="note" role="note"><span>Note:</span> This is required to allow direct nesting.
	Also, the "type selectors must come first" has no <em>intrinsic</em> reason behind it;
	it exists because we need to be able to tell simple selectors apart unambiguously
	when they’re directly appended together in a <a data-link-type="dfn" href="https://drafts.csswg.org/selectors-4/#compound" id="ref-for-compound②">compound selector</a>,
	and it’s not clear from <span class="css">.foodiv</span> that it should mean the same as <span class="css">div.foo</span>.
	An ampersand is unambiguously separable from an ident, tho,
	so there is no problem with it preceding a type selector,
	like <span class="css">&amp;div</span>.</p>
   <h2 class="heading settled" data-level="3" id="nesting"><span class="secno">3. </span><span class="content">Nesting Style Rules</span><a class="self-link" href="#nesting"></a></h2>
   <p>Nesting style rules naively inside of other style rules is, unfortunately, problematic—<wbr>the syntax of a selector is ambiguous with the syntax of a declaration,
	so an implementation requires unbounded lookahead
	to tell whether a given bit of text is a declaration or the start of a style rule.
	As CSS to date requires only a single token of lookahead in its parsing,
	this drawback is generally considered unacceptable among popular implementations of CSS.</p>
   <p>To get around this limitation,
	this specification defines two methods of <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="nested style rule|nesting style rule" data-noexport id="nested-style-rule">nesting style rules</dfn> inside of other style rules,
	both designed to be immediately unambiguous with the surrounding declarations.
	The first, <a data-link-type="dfn" href="#direct-nesting" id="ref-for-direct-nesting">direct nesting</a>,
	has a somewhat restricted syntax,
	but imposes minimal additional "weight" in the form of disambiguating syntax,
	and is suitable for most purposes.
	The second, the <a class="css" data-link-type="maybe" href="#at-ruledef-nest" id="ref-for-at-ruledef-nest">@nest</a> rule,
	imposes a small syntactic weight to disambiguate it from surrounding declarations,
	but has no restrictions on the makeup of the selector.
	The two are otherwise equivalent,
	and either can be used as desired by the stylesheet author.</p>
   <h3 class="heading settled" data-level="3.1" id="direct"><span class="secno">3.1. </span><span class="content">Direct Nesting</span><a class="self-link" href="#direct"></a></h3>
   <p>A style rule can be <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="direct nesting|directly nested" data-noexport id="direct-nesting">directly nested</dfn> within another style rule if its selector is <a data-link-type="dfn" href="#nest-prefixed" id="ref-for-nest-prefixed">nest-prefixed</a>.</p>
   <p>To be <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="nest-prefixed">nest-prefixed</dfn>,
	a <a data-link-type="dfn" href="#nesting-selector" id="ref-for-nesting-selector④">nesting selector</a> must be the first <a data-link-type="dfn" href="https://drafts.csswg.org/selectors-4/#simple" id="ref-for-simple">simple selector</a> in the first <a data-link-type="dfn" href="https://drafts.csswg.org/selectors-4/#compound" id="ref-for-compound③">compound selector</a> of the selector.
	If the selector is a list of selectors,
	every <a data-link-type="dfn" href="https://drafts.csswg.org/selectors-4/#complex" id="ref-for-complex">complex selector</a> in the list must be <a data-link-type="dfn" href="#nest-prefixed" id="ref-for-nest-prefixed①">nest-prefixed</a> for the selector as a whole to <span id="ref-for-nest-prefixed②">nest-prefixed</span>.</p>
   <div class="example" id="example-db70a34d">
    <a class="self-link" href="#example-db70a34d"></a> For example, the following nestings are valid: 
<pre class="lang-css highlight"><c- f>.foo </c-><c- p>{</c->
  <c- k>color</c-><c- p>:</c-> blue<c- p>;</c->
  &amp; > .bar { color: red; }
}
/* equivalent to
   .foo { color: blue; }
   .foo > .bar { color: red; }
 */

.foo {
  color: blue;
  &amp;.bar { color: red; }
}
/* equivalent to
   .foo { color: blue; }
   .foo.bar { color: red; }
 */

.foo, .bar {
  color: blue;
  &amp; + .baz, &amp;.qux { color: red; }
}
/* equivalent to
   .foo, .bar { color: blue; }
   :matches(.foo, .bar) + .baz,
   :matches(.foo, .bar).qux { color: red; }
 */
</pre>
    <p>But the following are invalid:</p>
<pre class="lang-css highlight"><c- f>.foo </c-><c- p>{</c->
  <c- k>color</c-><c- p>:</c-> red<c- p>;</c->
  .bar { color: blue; }
}
/* Invalid because there’s no nesting selector */

.foo {
  color: red;
  .bar &amp; { color:blue; }
}
/* Invalid because &amp; isn’t in the first compound selector */

.foo {
  color: red;
  &amp;.bar, .baz { color: blue; }
}
/* Invalid because the second selector in the list doesn’t
   contain a nesting selector. */
</pre>
   </div>
   <p class="note" role="note"><span>Note:</span> The last invalid example is technically not ambiguous,
	but it’s still invalid because allowing it would be an editing hazard.
	Later edits to the stylesheet might remove the first selector in the list,
	making the other one the new "first selector",
	and making the rule invalid.
	Turning an otherwise-innocuous action
	(like removing a selector from a list)
	into a possible error
	makes editing more complicated,
	and is author-hostile,
	so we disallow it as a possibility.</p>
   <h3 class="heading settled" data-level="3.2" id="at-nest"><span class="secno">3.2. </span><span class="content">The Nesting At-Rule: <a class="css" data-link-type="maybe" href="#at-ruledef-nest" id="ref-for-at-ruledef-nest①">@nest</a></span><a class="self-link" href="#at-nest"></a></h3>
   <p>While <a data-link-type="dfn" href="#direct-nesting" id="ref-for-direct-nesting①">direct nesting</a> looks nice,
	it is somewhat fragile.
	Some valid nesting selectors,
	like <span class="css">.foo &amp;</span>,
	are disallowed,
	and editing the selector in certain ways can make the rule invalid unexpectedly.
	As well,
	some people find the nesting challenging to distinguish visually
	from the surrounding declarations.</p>
   <p>To aid in all these issues,
	this specification defines the <a class="css" data-link-type="maybe" href="#at-ruledef-nest" id="ref-for-at-ruledef-nest②">@nest</a> rule,
	which imposes fewer restrictions on how to validly nest style rules.
	Its syntax is:</p>
<pre class="prod"><dfn class="dfn-paneled" data-dfn-type="at-rule" data-export id="at-ruledef-nest">@nest</dfn> = @nest <a class="production" data-link-type="type">&lt;selector></a> { <a class="production" data-link-type="type" href="https://drafts.csswg.org/css-syntax-3/#typedef-declaration-list" id="ref-for-typedef-declaration-list">&lt;declaration-list></a> }
</pre>
   <p>The <a class="css" data-link-type="maybe" href="#at-ruledef-nest" id="ref-for-at-ruledef-nest③">@nest</a> rule functions identically to a style rule:
	it starts with a selector,
	and contains declarations that apply to the elements the selector matches.
	The only difference is that the selector used in a <span class="css" id="ref-for-at-ruledef-nest④">@nest</span> rule
	must be <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="nest-containing">nest-containing</dfn>,
	which means it contains a <a data-link-type="dfn" href="#nesting-selector" id="ref-for-nesting-selector⑤">nesting selector</a> in it somewhere.
	A list of selectors is <a data-link-type="dfn" href="#nest-containing" id="ref-for-nest-containing">nest-containing</a> if all of its individual <a data-link-type="dfn" href="https://drafts.csswg.org/selectors-4/#complex" id="ref-for-complex①">complex selectors</a> are <span id="ref-for-nest-containing①">nest-containing</span>.</p>
   <div class="example" id="example-d07c256e">
    <a class="self-link" href="#example-d07c256e"></a> For example, the following nestings are valid: 
<pre class="lang-css highlight"><c- f>.foo </c-><c- p>{</c->
  <c- k>color</c-><c- p>:</c-> red<c- p>;</c->
  <c- n>@nest</c-> &amp; > .bar {
    color: blue;
  }
}
/* equivalent to
   .foo { color: red; }
   .foo > .bar { color: blue; }
 */

.foo {
  color: red;
  @nest .parent &amp; {
    color: blue;
  }
}
/* equivalent to
   .foo { color: red; }
   .parent .foo { color: blue; }
 */

.foo {
  color: red;
  @nest :not(&amp;) {
    color: blue;
  }
}
/* equivalent to
   .foo { color: red; }
   :not(.foo) { color: blue; }
 */
</pre>
    <p>But the following are invalid:</p>
<pre class="lang-css highlight"><c- f>.foo </c-><c- p>{</c->
  <c- k>color</c-><c- p>:</c-> red<c- p>;</c->
  <c- n>@nest</c-> .bar {
    color: blue;
  }
}
/* Invalid because there’s no nesting selector */

.foo {
  color: red;
  @nest &amp; .bar, .baz {
    color: blue;
  }
}
/* Invalid because not all selectors in the list
   contain a nesting selector */
</pre>
    <h3 class="heading settled" data-level="3.3" id="mixing"><span class="secno">3.3. </span><span class="content">Mixing Nesting Rules and Declarations</span><a class="self-link" href="#mixing"></a></h3>
    <p>A style rule can have any number of <a data-link-type="dfn" href="#nested-style-rule" id="ref-for-nested-style-rule②">nested style rules</a> inside of it,
	of either type,
	intermixed with any number of declarations,
	in any order.</p>
    <p>The relative ordering of <a data-link-type="dfn" href="#nested-style-rule" id="ref-for-nested-style-rule③">nested style rules</a> and other declarations <strong>is</strong> important;
	it’s possible for a given style rule and a <span id="ref-for-nested-style-rule④">nested style rule</span> within it to match the same element,
	and if the specificity of the two rules is otherwise equivalent,
	the relative order in the stylesheet of the applicable declarations
	determines which declaration "wins" the <a data-link-type="dfn" href="https://drafts.csswg.org/css-cascade-4/#cascade" id="ref-for-cascade">cascade</a>.</p>
    <h2 class="heading settled" data-level="4" id="cssom"><span class="secno">4. </span><span class="content">CSS Object Model Modifications</span><a class="self-link" href="#cssom"></a></h2>
    <div class="issue" id="issue-9d1e5685">
     <a class="self-link" href="#issue-9d1e5685"></a> 
     <ol>
      <li data-md>
       <p>Add an interface for the @nest rule.</p>
      <li data-md>
       <p>Tie into the general work needed to let rules be nested into style rules.</p>
     </ol>
    </div>
   </div>
  </main>
  <h2 class="no-ref no-num heading settled" id="conformance"><span class="content"> Conformance</span><a class="self-link" href="#conformance"></a></h2>
  <h3 class="heading settled" id="document-conventions"><span class="content"> Document conventions</span><a class="self-link" href="#document-conventions"></a></h3>
  <p>Conformance requirements are expressed with a combination of
	descriptive assertions and RFC 2119 terminology. The key words “MUST”,
	“MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”,
	“RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this
	document are to be interpreted as described in RFC 2119.
	However, for readability, these words do not appear in all uppercase
	letters in this specification. </p>
  <p>All of the text of this specification is normative except sections
	explicitly marked as non-normative, examples, and notes. <a data-link-type="biblio" href="#biblio-rfc2119">[RFC2119]</a> </p>
  <p>Examples in this specification are introduced with the words “for example”
	or are set apart from the normative text with <code>class="example"</code>,
	like this: </p>
  <div class="example" id="example-ae2b6bc0">
   <a class="self-link" href="#example-ae2b6bc0"></a> 
   <p>This is an example of an informative example. </p>
  </div>
  <p>Informative notes begin with the word “Note” and are set apart from the
	normative text with <code>class="note"</code>, like this: </p>
  <p class="note" role="note">Note, this is an informative note. </p>
  <p>Advisements are normative sections styled to evoke special attention and are
	set apart from other normative text with <code>&lt;strong class="advisement"></code>, like
	this: <strong class="advisement"> UAs MUST provide an accessible alternative. </strong> </p>
  <h3 class="heading settled" id="conform-classes"><span class="content"> Conformance classes</span><a class="self-link" href="#conform-classes"></a></h3>
  <p>Conformance to this specification
	is defined for three conformance classes: </p>
  <dl>
   <dt>style sheet 
   <dd>A <a href="http://www.w3.org/TR/CSS2/conform.html#style-sheet">CSS
			style sheet</a>. 
   <dt>renderer 
   <dd>A <a href="http://www.w3.org/TR/CSS2/conform.html#user-agent">UA</a> that interprets the semantics of a style sheet and renders
			documents that use them. 
   <dt>authoring tool 
   <dd>A <a href="http://www.w3.org/TR/CSS2/conform.html#user-agent">UA</a> that writes a style sheet. 
  </dl>
  <p>A style sheet is conformant to this specification
	if all of its statements that use syntax defined in this module are valid
	according to the generic CSS grammar and the individual grammars of each
	feature defined in this module. </p>
  <p>A renderer is conformant to this specification
	if, in addition to interpreting the style sheet as defined by the
	appropriate specifications, it supports all the features defined
	by this specification by parsing them correctly
	and rendering the document accordingly. However, the inability of a
	UA to correctly render a document due to limitations of the device
	does not make the UA non-conformant. (For example, a UA is not
	required to render color on a monochrome monitor.) </p>
  <p>An authoring tool is conformant to this specification
	if it writes style sheets that are syntactically correct according to the
	generic CSS grammar and the individual grammars of each feature in
	this module, and meet all other conformance requirements of style sheets
	as described in this module. </p>
  <h3 class="heading settled" id="conform-responsible"><span class="content"> Requirements for Responsible Implementation of CSS</span><a class="self-link" href="#conform-responsible"></a></h3>
  <p>The following sections define several conformance requirements
		for implementing CSS responsibly,
		in a way that promotes interoperability in the present and future. </p>
  <h4 class="heading settled" id="conform-partial"><span class="content"> Partial Implementations</span><a class="self-link" href="#conform-partial"></a></h4>
  <p>So that authors can exploit the forward-compatible parsing rules to assign fallback values, <strong>CSS renderers <em>must</em> treat as invalid
		(and <a href="http://www.w3.org/TR/CSS2/conform.html#ignore">ignore as appropriate</a>)
		any at-rules, properties, property values, keywords, and other syntactic constructs
		for which they have no usable level of support</strong>.
		In particular, user agents <em>must not</em> selectively ignore
		unsupported property values and honor supported values in a single multi-value property declaration:
		if any value is considered invalid (as unsupported values must be),
		CSS requires that the entire declaration be ignored. </p>
  <h4 class="heading settled" id="conform-future-proofing"><span class="content"> Implementations of Unstable and Proprietary Features</span><a class="self-link" href="#conform-future-proofing"></a></h4>
  <p>To avoid clashes with future stable CSS features,
		the CSSWG recommends <a href="http://www.w3.org/TR/CSS/#future-proofing">following best practices</a> for the implementation of <a href="http://www.w3.org/TR/CSS/#unstable">unstable</a> features and <a href="http://www.w3.org/TR/CSS/#proprietary-extension">proprietary extensions</a> to CSS. </p>
  <h4 class="heading settled" id="conform-testing"><span class="content"> Implementations of CR-level Features</span><a class="self-link" href="#conform-testing"></a></h4>
  <p>Once a specification reaches the Candidate Recommendation stage,
		implementers should release an <a data-link-type="dfn" href="http://www.w3.org/TR/CSS/#vendor-prefix">unprefixed</a> implementation
		of any CR-level feature they can demonstrate
		to be correctly implemented according to spec,
		and should avoid exposing a prefixed variant of that feature. </p>
  <p>To establish and maintain the interoperability of CSS across
		implementations, the CSS Working Group requests that non-experimental
		CSS renderers submit an implementation report (and, if necessary, the
		testcases used for that implementation report) to the W3C before
		releasing an unprefixed implementation of any CSS features. Testcases
		submitted to W3C are subject to review and correction by the CSS
		Working Group. </p>
  <p>
   Further information on submitting testcases and implementation reports
		can be found from on the CSS Working Group’s website at <a href="http://www.w3.org/Style/CSS/Test/">http://www.w3.org/Style/CSS/Test/</a>.
		Questions should be directed to the <a href="http://lists.w3.org/Archives/Public/public-css-testsuite">public-css-testsuite@w3.org</a> mailing list. 
<script src="https://www.w3.org/scripts/TR/2016/fixup.js"></script>
  </p>
  <h2 class="no-num no-ref heading settled" id="index"><span class="content">Index</span><a class="self-link" href="#index"></a></h2>
  <h3 class="no-num no-ref heading settled" id="index-defined-here"><span class="content">Terms defined by this specification</span><a class="self-link" href="#index-defined-here"></a></h3>
  <ul class="index">
   <li><a href="#selectordef-">&amp;</a><span>, in §2</span>
   <li><a href="#direct-nesting">directly nested</a><span>, in §3.1</span>
   <li><a href="#direct-nesting">direct nesting</a><span>, in §3.1</span>
   <li><a href="#at-ruledef-nest">@nest</a><span>, in §3.2</span>
   <li><a href="#nest-containing">nest-containing</a><span>, in §3.2</span>
   <li><a href="#nested-style-rule">nested style rule</a><span>, in §3</span>
   <li><a href="#nesting-selector">nesting selector</a><span>, in §2</span>
   <li><a href="#nested-style-rule">nesting style rule</a><span>, in §3</span>
   <li><a href="#nest-prefixed">nest-prefixed</a><span>, in §3.1</span>
  </ul>
  <aside class="dfn-panel" data-for="term-for-cascade">
   <a href="https://drafts.csswg.org/css-cascade-4/#cascade">https://drafts.csswg.org/css-cascade-4/#cascade</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-cascade">3.3. Mixing Nesting Rules and Declarations</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-propdef-color">
   <a href="https://drafts.csswg.org/css-color-4/#propdef-color">https://drafts.csswg.org/css-color-4/#propdef-color</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-propdef-color">2. Nesting Selector: the &amp; selector</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-typedef-declaration-list">
   <a href="https://drafts.csswg.org/css-syntax-3/#typedef-declaration-list">https://drafts.csswg.org/css-syntax-3/#typedef-declaration-list</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-typedef-declaration-list">3.2. The Nesting At-Rule: @nest</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-selectordef-matches">
   <a href="https://drafts.csswg.org/selectors-4/#selectordef-matches">https://drafts.csswg.org/selectors-4/#selectordef-matches</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-selectordef-matches">2. Nesting Selector: the &amp; selector</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-complex">
   <a href="https://drafts.csswg.org/selectors-4/#complex">https://drafts.csswg.org/selectors-4/#complex</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-complex">3.1. Direct Nesting</a>
    <li><a href="#ref-for-complex①">3.2. The Nesting At-Rule: @nest</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-compound">
   <a href="https://drafts.csswg.org/selectors-4/#compound">https://drafts.csswg.org/selectors-4/#compound</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-compound">2. Nesting Selector: the &amp; selector</a> <a href="#ref-for-compound①">(2)</a> <a href="#ref-for-compound②">(3)</a>
    <li><a href="#ref-for-compound③">3.1. Direct Nesting</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-simple">
   <a href="https://drafts.csswg.org/selectors-4/#simple">https://drafts.csswg.org/selectors-4/#simple</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-simple">3.1. Direct Nesting</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-specificity">
   <a href="https://drafts.csswg.org/selectors-4/#specificity">https://drafts.csswg.org/selectors-4/#specificity</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-specificity">2. Nesting Selector: the &amp; selector</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-type-selector">
   <a href="https://drafts.csswg.org/selectors-4/#type-selector">https://drafts.csswg.org/selectors-4/#type-selector</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-type-selector">2. Nesting Selector: the &amp; selector</a>
   </ul>
  </aside>
  <h3 class="no-num no-ref heading settled" id="index-defined-elsewhere"><span class="content">Terms defined by reference</span><a class="self-link" href="#index-defined-elsewhere"></a></h3>
  <ul class="index">
   <li>
    <a data-link-type="biblio">[css-cascade-4]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-cascade" style="color:initial">cascade</span>
    </ul>
   <li>
    <a data-link-type="biblio">[css-color-4]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-propdef-color" style="color:initial">color</span>
    </ul>
   <li>
    <a data-link-type="biblio">[css-syntax-3]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-typedef-declaration-list" style="color:initial">&lt;declaration-list></span>
    </ul>
   <li>
    <a data-link-type="biblio">[SELECTORS4]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-selectordef-matches" style="color:initial">:matches()</span>
     <li><span class="dfn-paneled" id="term-for-complex" style="color:initial">complex selector</span>
     <li><span class="dfn-paneled" id="term-for-compound" style="color:initial">compound selector</span>
     <li><span class="dfn-paneled" id="term-for-simple" style="color:initial">simple selector</span>
     <li><span class="dfn-paneled" id="term-for-specificity" style="color:initial">specificity</span>
     <li><span class="dfn-paneled" id="term-for-type-selector" style="color:initial">type selector</span>
    </ul>
  </ul>
  <h2 class="no-num no-ref heading settled" id="references"><span class="content">References</span><a class="self-link" href="#references"></a></h2>
  <h3 class="no-num no-ref heading settled" id="normative"><span class="content">Normative References</span><a class="self-link" href="#normative"></a></h3>
  <dl>
   <dt id="biblio-css-syntax-3">[CSS-SYNTAX-3]
   <dd>Tab Atkins Jr.; Simon Sapin. <a href="https://www.w3.org/TR/css-syntax-3/">CSS Syntax Module Level 3</a>. 20 February 2014. CR. URL: <a href="https://www.w3.org/TR/css-syntax-3/">https://www.w3.org/TR/css-syntax-3/</a>
   <dt id="biblio-css21">[CSS21]
   <dd>Bert Bos; et al. <a href="https://www.w3.org/TR/CSS2/">Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification</a>. 7 June 2011. REC. URL: <a href="https://www.w3.org/TR/CSS2/">https://www.w3.org/TR/CSS2/</a>
   <dt id="biblio-rfc2119">[RFC2119]
   <dd>S. Bradner. <a href="https://tools.ietf.org/html/rfc2119">Key words for use in RFCs to Indicate Requirement Levels</a>. March 1997. Best Current Practice. URL: <a href="https://tools.ietf.org/html/rfc2119">https://tools.ietf.org/html/rfc2119</a>
   <dt id="biblio-selectors4">[SELECTORS4]
   <dd>Elika Etemad; Tab Atkins Jr.. <a href="https://www.w3.org/TR/selectors-4/">Selectors Level 4</a>. 21 November 2018. WD. URL: <a href="https://www.w3.org/TR/selectors-4/">https://www.w3.org/TR/selectors-4/</a>
  </dl>
  <h3 class="no-num no-ref heading settled" id="informative"><span class="content">Informative References</span><a class="self-link" href="#informative"></a></h3>
  <dl>
   <dt id="biblio-css-cascade-4">[CSS-CASCADE-4]
   <dd>Elika Etemad; Tab Atkins Jr.. <a href="https://www.w3.org/TR/css-cascade-4/">CSS Cascading and Inheritance Level 4</a>. 28 August 2018. CR. URL: <a href="https://www.w3.org/TR/css-cascade-4/">https://www.w3.org/TR/css-cascade-4/</a>
   <dt id="biblio-css-color-4">[CSS-COLOR-4]
   <dd>Tab Atkins Jr.; Chris Lilley. <a href="https://www.w3.org/TR/css-color-4/">CSS Color Module Level 4</a>. 5 March 2019. WD. URL: <a href="https://www.w3.org/TR/css-color-4/">https://www.w3.org/TR/css-color-4/</a>
   <dt id="biblio-css3color">[CSS3COLOR]
   <dd>Tantek Çelik; Chris Lilley; David Baron. <a href="https://www.w3.org/TR/css-color-3/">CSS Color Module Level 3</a>. 19 June 2018. REC. URL: <a href="https://www.w3.org/TR/css-color-3/">https://www.w3.org/TR/css-color-3/</a>
  </dl>
  <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content">Issues Index</span><a class="self-link" href="#issues-index"></a></h2>
  <div style="counter-reset:issue">
   <div class="issue">
    <ol>
     <li data-md>
      <p>Add an interface for the @nest rule.</p>
     <li data-md>
      <p>Tie into the general work needed to let rules be nested into style rules.</p>
    </ol>
     <a href="#issue-9d1e5685"> ↵ </a>
   </div>
  </div>
  <aside class="dfn-panel" data-for="nesting-selector">
   <b><a href="#nesting-selector">#nesting-selector</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-nesting-selector">2. Nesting Selector: the &amp; selector</a> <a href="#ref-for-nesting-selector①">(2)</a> <a href="#ref-for-nesting-selector②">(3)</a> <a href="#ref-for-nesting-selector③">(4)</a>
    <li><a href="#ref-for-nesting-selector④">3.1. Direct Nesting</a>
    <li><a href="#ref-for-nesting-selector⑤">3.2. The Nesting At-Rule: @nest</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="selectordef-">
   <b><a href="#selectordef-">#selectordef-</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-selectordef-">2. Nesting Selector: the &amp; selector</a> <a href="#ref-for-selectordef-①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="nested-style-rule">
   <b><a href="#nested-style-rule">#nested-style-rule</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-nested-style-rule">2. Nesting Selector: the &amp; selector</a> <a href="#ref-for-nested-style-rule①">(2)</a>
    <li><a href="#ref-for-nested-style-rule②">3.3. Mixing Nesting Rules and Declarations</a> <a href="#ref-for-nested-style-rule③">(2)</a> <a href="#ref-for-nested-style-rule④">(3)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="direct-nesting">
   <b><a href="#direct-nesting">#direct-nesting</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-direct-nesting">3. Nesting Style Rules</a>
    <li><a href="#ref-for-direct-nesting①">3.2. The Nesting At-Rule: @nest</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="nest-prefixed">
   <b><a href="#nest-prefixed">#nest-prefixed</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-nest-prefixed">3.1. Direct Nesting</a> <a href="#ref-for-nest-prefixed①">(2)</a> <a href="#ref-for-nest-prefixed②">(3)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="at-ruledef-nest">
   <b><a href="#at-ruledef-nest">#at-ruledef-nest</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-at-ruledef-nest">3. Nesting Style Rules</a>
    <li><a href="#ref-for-at-ruledef-nest①">3.2. The Nesting At-Rule: @nest</a> <a href="#ref-for-at-ruledef-nest②">(2)</a> <a href="#ref-for-at-ruledef-nest③">(3)</a> <a href="#ref-for-at-ruledef-nest④">(4)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="nest-containing">
   <b><a href="#nest-containing">#nest-containing</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-nest-containing">3.2. The Nesting At-Rule: @nest</a> <a href="#ref-for-nest-containing①">(2)</a>
   </ul>
  </aside>
<script>/* script-dfn-panel */

document.body.addEventListener("click", function(e) {
    var queryAll = function(sel) { return [].slice.call(document.querySelectorAll(sel)); }
    // Find the dfn element or panel, if any, that was clicked on.
    var el = e.target;
    var target;
    var hitALink = false;
    while(el.parentElement) {
        if(el.tagName == "A") {
            // Clicking on a link in a <dfn> shouldn't summon the panel
            hitALink = true;
        }
        if(el.classList.contains("dfn-paneled")) {
            target = "dfn";
            break;
        }
        if(el.classList.contains("dfn-panel")) {
            target = "dfn-panel";
            break;
        }
        el = el.parentElement;
    }
    if(target != "dfn-panel") {
        // Turn off any currently "on" or "activated" panels.
        queryAll(".dfn-panel.on, .dfn-panel.activated").forEach(function(el){
            el.classList.remove("on");
            el.classList.remove("activated");
        });
    }
    if(target == "dfn" && !hitALink) {
        // open the panel
        var dfnPanel = document.querySelector(".dfn-panel[data-for='" + el.id + "']");
        if(dfnPanel) {
            dfnPanel.classList.add("on");
            var rect = el.getBoundingClientRect();
            dfnPanel.style.left = window.scrollX + rect.right + 5 + "px";
            dfnPanel.style.top = window.scrollY + rect.top + "px";
            var panelRect = dfnPanel.getBoundingClientRect();
            var panelWidth = panelRect.right - panelRect.left;
            if(panelRect.right > document.body.scrollWidth && (rect.left - (panelWidth + 5)) > 0) {
                // Reposition, because the panel is overflowing
                dfnPanel.style.left = window.scrollX + rect.left - (panelWidth + 5) + "px";
            }
        } else {
            console.log("Couldn't find .dfn-panel[data-for='" + el.id + "']");
        }
    } else if(target == "dfn-panel") {
        // Switch it to "activated" state, which pins it.
        el.classList.add("activated");
        el.style.left = null;
        el.style.top = null;
    }

});
</script>